package launcher;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;

import constants.FileNodeConstants;
import constants.NetworkConstants;

public class CommandLineParameters {

	private Options commandLineOptions ;
	
	public CommandLineParameters() {
		this.commandLineOptions = new Options();
		this.setOptions();
	}
	private void setOptions(){
		this.commandLineOptions.addOption(FileNodeConstants.PARAM_HB_PORT, true, "Override Heartbeat port number to be used");
		this.commandLineOptions.addOption(FileNodeConstants.PARAM_GOV_IP,true, "IP adddress or hostname for governor (Multicast Address)") ;
		this.commandLineOptions.addOption(FileNodeConstants.PARAM_FU_PORT,true,"Override default file upload port number");
		this.commandLineOptions.addOption(FileNodeConstants.PARAM_FD_PORT,true,"Override default file download port number");
		this.commandLineOptions.addOption(FileNodeConstants.PARAM_COMMAND_PORT, true, "Overide Command port number");
	}
	public Options getCommandLineOptions(){
		return this.commandLineOptions;
	}
	public Map<String,String> getFileNodeParameters(CommandLine command){
		HashMap<String,String> mapOfParameters = new HashMap<String, String>();
		mapOfParameters.put(FileNodeConstants.PARAM_COMMAND_PORT, (String)(command.hasOption(FileNodeConstants.PARAM_COMMAND_PORT)?command.getOptionValue(FileNodeConstants.PARAM_COMMAND_PORT):Integer.toString(NetworkConstants.DEFAULT_COMMAND_PORT)));
		mapOfParameters.put(FileNodeConstants.PARAM_FU_PORT, (String)(command.hasOption(FileNodeConstants.PARAM_FU_PORT)?command.getOptionValue(FileNodeConstants.PARAM_FU_PORT):Integer.toString(NetworkConstants.DEFAULT_FU_PORT)));
		mapOfParameters.put(FileNodeConstants.PARAM_FD_PORT, (String)(command.hasOption(FileNodeConstants.PARAM_FD_PORT)?command.getOptionValue(FileNodeConstants.PARAM_FD_PORT):Integer.toString(NetworkConstants.DEFAULT_FD_PORT)));
		mapOfParameters.put(FileNodeConstants.PARAM_HB_PORT, (String)(command.hasOption(FileNodeConstants.PARAM_HB_PORT)?command.getOptionValue(FileNodeConstants.PARAM_HB_PORT):Integer.toString(NetworkConstants.DEFAULT_HB_PORT+1)));
		if(command.hasOption(FileNodeConstants.PARAM_GOV_IP)){
			mapOfParameters.put(FileNodeConstants.PARAM_GOV_IP, (String)command.getOptionValue(FileNodeConstants.PARAM_COMMAND_PORT));
		}
		return mapOfParameters;
	}
	
}
